/*
 * Copyright (C) 2008 Peter Kling
 *
 * This file is part of 'A Kind of Billiard', a graphical billiard simulation.
 *
 * 'A Kind of Billiard' is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * 'A Kind of Billiard' is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * 'A Kind of Billiard'. If not, see <http://www.gnu.org/licenses/>.
 */

package cg2.misc;

import java.util.ArrayList;

import javax.media.opengl.GL;

/**
 * @brief This class allows to collect several OpenGLDrawables into one group and have them drawn all by once.
 * 
 * This can be used for example to shade a group of objects together.
 */
public class OpenGLDrawableGroup implements OpenGLDrawable {
	private ArrayList<OpenGLDrawable> drawables = new ArrayList<OpenGLDrawable>();
	
	/**
	 * @brief Draws all objects of this group.
	 */
	public void draw(GL gl) {
		for (OpenGLDrawable drawable : drawables) {
			drawable.draw(gl);
		}
	}
	
	/**
	 * @brief Adds the given OpenGL drawable to this group.
	 */
	public void add(OpenGLDrawable drawable) {
		drawables.add(drawable);
	}
	
	/**
	 * @brief Removes the given OpenGL drawable from this group.
	 */
	public void remove(OpenGLDrawable drawable) {
		drawables.remove(drawable);
	}
}
